package dongchel.vrp.localsearch;

import dongchel.vrp.entity.Route;
import dongchel.vrp.entity.Solution;

public class Move {
	private int routeIndexFrom;
	private int cityIndexFrom;
	
	private int routeIndexTo;
	private int cityIndexTo;
	
	public static Move randomGeneMove(Solution solution){
		int routeIndexFrom = (int)Math.floor(Math.random()*solution.getRouteList().size());
		Route route = solution.getRouteList().get(routeIndexFrom);
		int cityIndexFrom = (int)Math.floor(Math.random()*(route.getCityList().size()-2))+1;
		
		int routeIndexTo = (int)Math.floor(Math.random()*solution.getRouteList().size());
		route = solution.getRouteList().get(routeIndexTo);
		int cityIndexTo = (int)Math.floor(Math.random()*(route.getCityList().size()-2))+1;
		if((routeIndexTo == routeIndexFrom && cityIndexTo == cityIndexFrom)){
			return randomGeneMove(solution);
		}else{
			Move move = new Move();
			move.setCityIndexFrom(cityIndexFrom);
			move.setCityIndexTo(cityIndexTo);
			move.setRouteIndexFrom(routeIndexFrom);
			move.setRouteIndexTo(routeIndexTo);
			return move;
		}
	}
	
	
	public boolean checkDuplicate(Move move){
		if(this.routeIndexFrom == move.routeIndexFrom && this.cityIndexFrom == move.cityIndexFrom){
			return true;
		}
		
		if(this.routeIndexTo == move.routeIndexTo && this.cityIndexTo == move.cityIndexTo){
			return true;
		}
		return false;
	}
	
	public int getRouteIndexFrom() {
		return routeIndexFrom;
	}
	public void setRouteIndexFrom(int routeIndexFrom) {
		this.routeIndexFrom = routeIndexFrom;
	}
	public int getCityIndexFrom() {
		return cityIndexFrom;
	}
	public void setCityIndexFrom(int cityIndexFrom) {
		this.cityIndexFrom = cityIndexFrom;
	}
	public int getRouteIndexTo() {
		return routeIndexTo;
	}
	public void setRouteIndexTo(int routeIndexTo) {
		this.routeIndexTo = routeIndexTo;
	}
	public int getCityIndexTo() {
		return cityIndexTo;
	}
	public void setCityIndexTo(int cityIndexTo) {
		this.cityIndexTo = cityIndexTo;
	}
}
